//
//  DDStackView.swift
//  swift微博
//
//  Created by whitcast on 16/7/21.
//  Copyright © 2016年 whitcast. All rights reserved.
//

import UIKit
//按钮的类型
enum emojiButtonType: Int {
    //默认
    case normalButton = 1000
    //emoji
    case emojiButton = 1001
    //浪小花
    case lxhButton = 1002
}

class DDStackView: UIStackView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        //设置
        setupUI()
        //设置stackView
        self.axis = .Horizontal
        //填充模式
        distribution = .FillEqually
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    //设置
    private func setupUI(){
        //创建
        let normalBtn = creatBtn("默认",type: .normalButton)
        
        let emojiBtn = creatBtn("Emoji",type: .emojiButton)
        
        let LXHbtn = creatBtn("浪小花",type: .lxhButton)
        //添加
        addArrangedSubview(normalBtn)
        addArrangedSubview(emojiBtn)
        addArrangedSubview(LXHbtn)
    }
    //创建控件
    private func creatBtn(title: String,type: emojiButtonType)->UIButton{
        let btn = UIButton()
        btn.setTitle(title, forState: .Normal)
        
        btn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Selected)
        
        btn.setTitleColor(UIColor.darkGrayColor(),forState: UIControlState.Normal)
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Selected)
        //tag赋值
        btn.tag = type.rawValue
        //点击事件
        btn.addTarget(self, action: "buttonClick:", forControlEvents: .TouchUpInside)
        return btn
        
    }
// MARK:--按钮的点击事件
   @objc private func buttonClick(button: UIButton){
        print("emoji键盘toolbar的点击事件")
        
    }
    
}
